package com.itheima.youdianda.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult implements Serializable {
    //总条数
    private Long count;
    //当前页数
    private Long currentPage;
    //页大小
    private Long pageSize;
    //总页数
    private Long totalPages;

    private List data;


    public static PageResult init(Long counts, Long pageSize, Long currentPage, List data) {
        long totalPage = counts % pageSize == 0 ? counts / pageSize : counts / pageSize + 1;

        return new PageResult(counts, currentPage, pageSize, totalPage, data);
    }

    public static PageResult init(Page page) {

        long totalPage = page.getTotal() % page.getSize() == 0 ? page.getTotal() / page.getSize() : page.getTotal() / page.getSize() + 1;
        return new PageResult(page.getTotal(), page.getCurrent(), page.getSize(), totalPage, page.getRecords());

    }

}
